using System;
using System.Collections.Generic;
using System.Text;
using MSLogging = Microsoft.Practices.EnterpriseLibrary.Logging;
using System.Web;
using System.Web.Security;
namespace NiSis.Loggin
{
    public class Logger
    {
        static MSLogging.LogEntry log = new MSLogging.LogEntry();

        public static void Conferma( string message)
        {
            string user = HttpContext.Current.User.Identity.Name;
            MSLogging.LogEntry log = new MSLogging.LogEntry();
            log.Severity = System.Diagnostics.TraceEventType.Information;
            log.Title = "Conferma";
            log.Message=string.Format("Utente:{0}, Messaggio: {1}",user,message);
            log.Priority=1;
            
            MSLogging.Logger.Write(log.Message,"Conferma");
        }

        public static void Inconsistenza(int eventID, string message)
        {
            string user = HttpContext.Current.User.Identity.Name;
            log.Severity = System.Diagnostics.TraceEventType.Warning;
            log.Message = string.Format("Utente:{0}, Inconsistenza: {1}", user, message);
            log.Title = "Inconsistenza";
            MSLogging.Logger.Write(log.Message,"Inconsistenza");
        }

        public static void ErroreGrave(string message, Exception ex)
        {
            string user = HttpContext.Current.User.Identity.Name;
            log.Title = "Errore grave";
            log.Message = string.Format("Utente:{0}, {1} Messaggio Errore:{2}",user,message,ex.Message);
            log.AddErrorMessage(ex.StackTrace);
            log.Severity = System.Diagnostics.TraceEventType.Error;
            

            MSLogging.Logger.Write(log.Message,"Errore Grave");
        }

        public static void Debug(int eventID, string message, string debug)
        {
#if DEBUG
            log.EventId = eventID;
            log.Message = message;

            MSLogging.Logger.Write(log);
#endif
        }
    }
}
